
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="page/head.jsp" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div class="container">

    <div style="text-align: center"><h2>图书详细列表</h2></div>
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <table class="table table-bordered table-hover">
                <thead>
                <tr>
                    <th>书名</th>
                    <th>作者</th>
                    <th>出版社</th>
                    <th>出版日期</th>
                    <th>页数</th>
                    <th>价格</th>
                    <th>内容摘要</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="b" items="${info.list}">
                <tr>
                    <td>${b.name}</td>
                    <td>${b.author}</td>
                    <td>${b.publish}</td>
                    <td>
                        <fm:formatDate value="${b.publishdate}" pattern="yyyy-MM-dd"/>
                    </td>
                    <td>${b.page}</td>
                    <td>${b.price}</td>
                    <td>${b.content}</td>
                    <td>
                        <button type="button" class="btn btn-danger" onclick="del(${b.id})">删除</button>
                        <button type="button" class="btn btn-warning" onclick="updateEmp(${b.id})">修改</button>
                    </td>
                </tr>
                </c:forEach>
                </tbody>
                <tfoot>
                <tr align="center">
                    <td colspan="8">
                        <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <li>
                                   <a href="/addBook.jsp" style="background-color: forestgreen ;color: white">新增图书</a>
                                </li>
                                <li>
                                    <a><span>共${info.total}条记录</span></a>
                                </li>
                                <li>
                                    <a style="padding: 3px 12px">每页<input id="inputnum" type="number" name="inputnum" value="${sessionScope.pagesize}" style="width: 50px">条</a>
                                </li>
                                <li>
                                    <a>当前第${info.pageNum}页/总共${info.pages}页</a>
                                </li>
                                <li>
                                    <a href="/book/getBookByPage?pageNum=1" aria-label="Previous">
                                        <span aria-hidden="true">第一页</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="/book/getBookByPage?pageNum=${info.prePage}" aria-label="Previous">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>

                                <li>
                                    <a href="/book/getBookByPage?pageNum=${info.nextPage}" aria-label="Next">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="/book/getBookByPage?pageNum=${info.pages}" aria-label="Next">
                                        <span aria-hidden="true">最后一页</span>
                                    </a>
                                </li>
                                <li>
                                <li style="padding: 3px 12px">
                                    <a>
                                        转到<input id="inputpage" type="number" name="inputpage" style="width: 50px">页
                                        <button id="but">go</button>
                                    </a>
                                </li>
                                </li>
                            </ul>
                        </nav>
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>
<script>
    
    function del(id) {
        if (confirm("是否确认删除")) {
            $.ajax({
                url:"/book/delBook?id="+id,
                type:"get",
                success:function (result) {
                    if (result==1) {
                       alert("删除成功");
                       location.reload();
                    }else{
                        alert("删除失败");
                    }
                }
            })
        }
    }

    function updateEmp(book) {

        location.href="/book/getBookById?id="+book;
    }

    $(function () {
        $("#inputnum").change(function () {
            if ($(this).val()<=1){
                $(this).val("1");
            }
            location.href="/book/getBookByPage?pageSize="+$(this).val()+"&pageNum="+${info.pageNum}
        })




        $("#but").click(function () {
            location.href="/book/getBookByPage?pageNum="+$("#inputpage").val();
        })

    })
    
    
</script>
</body>
</html>
